{include file="public_header" title="退库" /}
  <div class="main">
    <div class="notice"> 您当前的位置：<a href="{:url('common/index')}">首页</a> &gt; <a href="{:url('sku/quit')}" class="v-link-active">退库</a> </div>
    <div class="main_content">
      <div class="title"> <span>高级搜索</span> </div>
      <form class="layui-form">
        <div class="layui-inline mr10">
          <div class="layui-input-inline">
            <select name="plat_name" lay-verify="required" lay-search="">
              <option value="">所属平台</option>              
              {volist name="plat_list_select" id="vo"}
                <option value="{$vo.id}" {if condition="$plat_id eq $vo.id"}selected{/if}>{$vo.plat_name}</option>
              {/volist}
            </select>
          </div>
        </div>
        <div class="layui-inline mr15">
          <div class="layui-input-inline">
            <select name="custom_id" lay-verify="required" lay-search="">
              <option value="">客户名称</option>              
              {volist name="customer_name_list" id="vo"}
                <option value="{$vo.id}" {if condition="$custom_id eq $vo.id"}selected{/if}>{$vo.customer_name}</option>
              {/volist}
            </select>
          </div>
        </div>      
        <div class="layui-inline">
          <label class="layui-form-label">序列号</label>
          <div class="layui-input-inline">
            <input type="text" name="card_id" placeholder="序列号" autocomplete="off" class="layui-input" value="{$card_id}">
          </div>
        </div>   
        <div class="layui-inline">
          <label class="layui-form-label">退回日期</label>
          <div class="layui-input-inline">
            <input type="text" name="return_time" class="layui-input" id="test16" placeholder="开始 到 结束" value="{$return_time}">
          </div>
        </div>    
        <button class="layui-btn" data-type="reload">搜索</button>         
      </form>
      <div class="title mt20"> <span>退库</span> </div>
	  {if condition="(in_array('Sku/quit_add',$user['account_auth'])) and ($user['position'] neq 1)"}
      <a class="btn mr10" id="add-return" href="javascript:;">添加</a>
	  {elseif condition="$user['position'] eq 1"/}
	    <a class="btn mr10" id="add-return" href="javascript:;">添加</a>
	  {/if}

    {if condition="(in_array('Sku/quit_del',$user['account_auth'])) and ($user['position'] neq 1)"}
      <a class="btn do-action mr10" href="javascript:;" data-type="doStateAll" data-href="{:url('sku/edit_state')}?state=4">退库</a>    
    {elseif condition="$user['position'] eq 1"/}
      <a class="btn do-action mr10" href="javascript:;" data-type="doStateAll" data-href="{:url('sku/edit_state')}?state=4">退库</a>    
    {/if}

	  {if condition="(in_array('Sku/quit_del',$user['account_auth'])) and ($user['position'] neq 1)"}
      <a class="btn do-action" href="javascript:;" data-type="doDelete" data-href="{:url('sku/quit_del')}">删除</a>	   
	  {elseif condition="$user['position'] eq 1"/}
	    <a class="btn do-action" href="javascript:;" data-type="doDelete" data-href="{:url('sku/quit_del')}">删除</a>	   
	  {/if}
      <div class="table">
        <table class="layuitable">
          <thead>
            <tr>
              <th width="50"><input type="checkbox" name=""></th>
              <th class="sort" width="80"><span>编号</span></th>
              <th class="sort" width="100"><span>客户名称</span></th>
              <th class="sort" width="100"><span>平台名称</span></th>
              <th class="sort" width="100"><span>序列号</span></th>
              <th class="sort" width="80"><span>退回日期</span></th>
              <th class="sort" width="80"><span>备注</span></th>
              <th class="sort" width="120"><span>状态</span></th>              
              <th width="150"><span>操作</span></th>
            </tr>
          </thead>
          <tbody>
		  {volist name="quit_list" id="vo"}
            <tr>
              <td><input type="checkbox" name="ck" ids="{$vo['id']}" value="true"></td>
              <td>{$vo.id}</td>
              <td>{$vo.custom_id}</td>
              <td>{$vo.plat_id}</td>
              <td>{$vo.card_id}</td>
              <td>{$vo.return_time|date="Y-m-d",###}</td>
              <td>{$vo.remark}</td>
              <td><a class="blue" href="javascript:;">{$vo.state}</a></td>              
              <td>
			<!--   <a class="blue guaqi do-action" href="javascript:;" data-type="doState" data-href="{:url('sku/edit_state')}?state=3" data-id="{$vo['id']}">挂起</a>     -->	  
				<a class="blue tuiku do-action" href="javascript:;" data-type="doState" data-href="{:url('sku/edit_state')}?state=4" data-id="{$vo['id']}">退库</a>
			  </td>
            </tr>  
		  {/volist}
          </tbody>
        </table>
      </div>
      <div class="page fr">
          <?php
            $fist_page = ($page == 1 ? 'no' : '1');
            $bottom_page = ($page == 1 ? 'no' : $page-1);
            echo("<a class=\"page_first\" href=\"javascript:gopage('".$fist_page."');\">&laquo;</a>");
            echo("<a class=\"page_prev\" href=\"javascript:gopage('".$bottom_page."');\">&lsaquo;</a>");
          ?>
          <div class="pages">
            <?php for($i = 1 ; $i <= ceil($count/20);$i++) {
              if($page == $i){
                echo("<a class=\"in\" href=\"javascript:gopage('no');\">$i</a>");
              }else{
                echo("<a href=\"javascript:gopage('".$i."');\">$i</a>");
              }
             } ?>
           </div>
           <?php
           $last_page = ($page == ceil($count/20) ? 'no' : ceil($count/20));
           $top_page = ($page == ceil($count/20) ? 'no' : $page+1);
           echo("<a class=\"page_first\" href=\"javascript:gopage('".$top_page."');\">&rsaquo;</a>");
           echo("<a class=\"page_prev\" href=\"javascript:gopage('".$last_page."');\">&raquo;</a>");
         ?> 
        </div>
      <div class="clear"></div>     
    </div>
  </div>
</div>
<div id="set-add-return" style="display:none; width:550px; padding:20px;">
  <form class="layui-form" action="#" method="post" id="doAdd">
    <div class="layui-form-item">
      <div class="layui-inline">
        <label class="layui-form-label">序列号</label>
        <div class="layui-input-inline" style="width: 100px;">
          <input type="text" name="card_id1" placeholder="起" autocomplete="off" class="layui-input" lay-verify="card_id1">
        </div>
        <div class="layui-form-mid">-</div>
        <div class="layui-input-inline" style="width: 100px;">
          <input type="text" name="card_id2" placeholder="止" autocomplete="off" class="layui-input" lay-verify="card_id2">
        </div>
        <div class="layui-form-mid layui-word-aux">按范围填写</div>        
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">序列号</label>
      <div class="layui-input-inline">
        <input type="text" name="card_id" lay-verify="card_id" autocomplete="off" placeholder="请输入序列号" class="layui-input">
      </div>
      <div class="layui-form-mid layui-word-aux">按单个填写</div>
    </div>    
    <div class="layui-form-item">
      <label class="layui-form-label">退回日期</label>
      <div class="layui-input-inline">
        <input type="text" name="return_time" class="layui-input" id="test1" placeholder="yyyy-MM-dd" lay-verify="required" value="<?php echo date('Y-m-d')?>">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">状态</label>
      <div class="layui-input-inline">
        <input type="radio" name="status" value="0" title="挂起" checked="">
        <input type="radio" name="status" value="1" title="退库">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">备注</label>
      <div class="layui-input-inline">
        <textarea placeholder="请输入备注" name="remark" lay-verify="remark" class="layui-textarea"></textarea>
      </div>
    </div> 
    <div>
      <button class="layui-btn layui-btn ml80" lay-submit lay-filter="form">提交</button>
    </div>
  </form>
</div>
<script>
//页面层
  $('#add-return').on('click', function(){
    layer.open({
      type: 1,
      area: ['550px', '480px'],
      shadeClose: true, //点击遮罩关闭
      content: $('#set-add-return')
    });
  });
layui.use('form', function(){
	var form = layui.form;
	var verify = function (obj) {
	    obj.addClass('layui-form-danger')
	        .focus()
	        .one('input',function () {
	            obj.removeClass('layui-form-danger').next('span').fadeOut();
	        })
	        .next('span').slideDown('fast');
	}
	form.on('submit(form)', function(data){
    layer.msg('添加中，请稍后..', {
      icon: 16
      ,shade: 0.01
      ,time:360000
    });
		$.ajax({
	        url:"{:url('sku/quit_add')}",
			type:'POST',
	        data:$('#doAdd').serialize(),
	        dataType:"json",
	        error:function(data){
	            common.layerAlertE('链接错误！', '提示');
	        },
	        success:function(data){
            layer.close(layer.index);
	            if(data.code==1){
	                layer.alert(data.msg, {icon: 6}, function(index){
	                    layer.close(index);
	                    window.location.href = "{:url('sku/quit')}";
	                });
	            }else{
	                layer.alert(data.msg, {icon: 5});
	                return false;
	            }
	        }
	    });
	    return false;
	});
});
layui.use('laydate', function(){
  var laydate = layui.laydate;
  laydate.render({
    elem: '#test16'
    ,type: 'datetime'
    ,range: ','
    ,format: 'yyyy-M-d'
  });
  laydate.render({
    elem: '#test1'
  });   
}); 
//分页
function gopage(page){
  if(page == "no"){
    alert('您已在这一页');
    return false;
  }
  window.location.href="{:url('sku/quit')}?plat_name={$plat_id}&custom_id={$custom_id}&card_id={$card_id}&return_time={$return_time}&page="+page;
}

//只显示相近的左右各五个分页按钮
$(function(){
  var page = "<?php echo($page);?>";
  if('<?php echo(ceil($count/20));?>' > 11){
    $('.pages>a').hide();
    $('.pages>a:eq('+(page-1)+')').show();
    for(var i = 1 ; i <= 5 ; i++){
      if(((page-1)-i) >= 0){
        $('.pages>a:eq('+((page-1)-i)+')').show();
      }
      if(((page-1)+i) <= '<?php echo(ceil($count/20));?>'){
        $('.pages>a:eq('+((page-1)+i)+')').show();
      }
    }
  }
}); 
//弹出一个页面层
$('.tuiku').on('click', function(){
layer.confirm('您确定要退库吗', {
  btn: ['退库','挂起','取消'] //按钮
}, function(){
  layer.msg('退库成功', {icon: 1});
}, function(){
  layer.msg('挂起成功', {icon: 1});
}, function(){
});
});
</script>
</body>
</html>